package com.zx.auth.block.modle;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;


/**
 * <p>
 * description: OAuth2 授权同意实体类，对应数据库表 oauth2_authorization_consent，存储用户对客户端的授权同意信息 <br>
 * create: 2025-04-25 10:37 <br>
 * </p>
 *
 * @author zhou  xun
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "oauth2_authorization_consent")
@IdClass(OAuth2AuthorizationConsent.IdClass.class)
public class OAuth2AuthorizationConsent implements Serializable {

    /**
     * 关联的客户端ID
     */
    @Id
    @Column(name = "registered_client_id", length = 100, nullable = false)
    private String registeredClientId;

    /* 复合主键部分 */
    /**
     * 授权主体名称(通常是用户名)
     */
    @Id
    @Column(name = "principal_name", length = 200, nullable = false)
    private String principalName;
    /**
     * 授予的权限列表，存储为逗号分隔的字符串
     */
    @Column(name = "authorities", length = 1000, nullable = false)
    private String authorities;

    /**
     * 租户ID
     */
    @Column(name = "tenant_id", length = 32, nullable = false)
    private String tenantId;

    /* 业务字段 */

    /**
     * 复合主键类
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class IdClass implements Serializable {
        /**
         * 关联的客户端ID
         */
        private String registeredClientId;

        /**
         * 授权主体名称(通常是用户名)
         */
        private String principalName;
    }
}